package com.orangelife.service.cerHouseholder.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.orangelife.common.MybaitsGenericDaoSubLogic;
import com.orangelife.exception.AppBizException;
import com.orangelife.service.cerHouseholder.ICerHouseholderService;
import com.orangelife.service.cerHouseholder.model.CerHouseholderDto;
import com.orangelife.service.propFeeApartment.IPropFeeApartmentService;
import com.orangelife.service.propFeeApartment.model.PropFeeApartmentDto;
import com.orangelife.service.propFeeBuilding.IPropFeeBuildingService;
import com.orangelife.service.propFeeBuilding.model.PropFeeBuildingDto;
import com.orangelife.service.propFeeComm.IPropFeeCommService;
import com.orangelife.service.propFeeComm.model.PropFeeCommDto;
import com.orangelife.service.propFeeUnit.IPropFeeUnitService;
import com.orangelife.service.propFeeUnit.model.PropFeeUnitDto;
import com.orangelife.setting.constant.CodeConst;
import com.orangelife.setting.constant.InfoConst;
import com.orangelife.setting.constant.TypeConst;
import com.orangelife.utils.IdUtil;
import com.orangelife.utils.StringUtils;

/*****************************************************************
 * Copyright(C) ORANGELIFE Corporation CodeConst.BIS_CODE_68001015. All Rights
 * Reserved.
 *****************************************************************/
/*
 * ============================================================== 功能名
 * CerHouseholder类的 service层的增删改查
 * 
 * @author @author zhr
 * 
 * @version 1.1.0
 * 
 * @date 2016-06-17 13:50:34
 * ==============================================================
 */
@Service("cerHouseholderService")
public class CerHouseholderServiceImpl extends MybaitsGenericDaoSubLogic
		implements ICerHouseholderService {

	@Resource(name = "propFeeApartmentService")
	private IPropFeeApartmentService propFeeApartmentService;

	/***
	 * 初始化楼栋
	 */

	@Resource(name = "propFeeBuildingService")
	private IPropFeeBuildingService propFeeBuildingService;
	@Resource(name = "propFeeCommService")
	private IPropFeeCommService propFeeCommService;
	/***
	 * 初始化单元
	 */
	@Resource(name = "propFeeUnitService")
	private IPropFeeUnitService propFeeUnitService;
	private static Logger logger = Logger
			.getLogger(CerHouseholderServiceImpl.class);

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		CerHouseholderServiceImpl.logger = logger;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int addCerHouseholder(CerHouseholderDto cerHouseholder)
			throws AppBizException {

		Assert.notNull(cerHouseholder);
		/************************************************
		 * 判断输入参数的长度以及是否能为空
		 ************************************************/

		if (!StringUtils.isBlank(cerHouseholder.getType())) {
			if (cerHouseholder.getType().length() > 1) {
				throw new AppBizException(CodeConst.SYS_CODE_1002,
						"1户主，2家属,3租客，4其他长度超出");
			}
		}

		if (!StringUtils.isBlank(cerHouseholder.getName())) {
			if (cerHouseholder.getName().length() > 36) {
				throw new AppBizException(CodeConst.SYS_CODE_1002, "姓名长度超出");
			}
		}

		if (!StringUtils.isBlank(cerHouseholder.getPhone())) {
			if (cerHouseholder.getPhone().length() > 20) {
				throw new AppBizException(CodeConst.SYS_CODE_1002, "手机号码长度超出");
			}
		}

		if (StringUtils.isBlank(cerHouseholder.getHouseholderID())) {
			cerHouseholder.setHouseholderID(IdUtil.getuuId());
		}
		cerHouseholder.setItemStat(TypeConst.FLAG_ON);
		cerHouseholder.setTscreate(new Date());
		cerHouseholder.setTsedit(new Date());
		return this.getSqlSession().insert(
				"CerHouseholderMapper.insertSelective", cerHouseholder);
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editCerHouseholder(CerHouseholderDto cerHouseholder)
			throws AppBizException {

		Assert.notNull(cerHouseholder);
		/************************************************
		 * 判断输入参数的长度以及是否能为空
		 ************************************************/
		if (StringUtils.isBlank(cerHouseholder.getHouseholderID())) {
			throw new AppBizException(CodeConst.SYS_CODE_1001, "ID不可为空");
		}
		CerHouseholderDto oldCerHouseholder = this
				.findCerHouseholderByID(cerHouseholder.getHouseholderID());

		if (!StringUtils.isBlank(cerHouseholder.getType())) {
			if (cerHouseholder.getType().length() > 1) {
				throw new AppBizException(CodeConst.SYS_CODE_1002,
						"1户主，2家属,3租客，4其他长度超出");
			}
		}

		if (!StringUtils.isBlank(cerHouseholder.getName())) {
			if (cerHouseholder.getName().length() > 36) {
				throw new AppBizException(CodeConst.SYS_CODE_1002, "姓名长度超出");
			}
		}

		if (!StringUtils.isBlank(cerHouseholder.getPhone())) {
			if (cerHouseholder.getPhone().length() > 20) {
				throw new AppBizException(CodeConst.SYS_CODE_1002, "手机号码长度超出");
			}
		}

		if (oldCerHouseholder == null) {
			throw new AppBizException(CodeConst.BIS_CODE_68001,
					InfoConst.BIS_INFO_68001);
		}
		cerHouseholder.setTsedit(new Date());
		return this.getSqlSession().update(
				"CerHouseholderMapper.updateByPrimaryKeySelective",
				cerHouseholder);
	}

	@Override
	public CerHouseholderDto findCerHouseholderByID(String cerHouseholderID)
			throws AppBizException {
		if (StringUtils.isBlank(cerHouseholderID)) {

			throw new AppBizException(CodeConst.SYS_CODE_1001, "ID不可为空");
		}

		/************************************************
		 * 判断实体是否存在
		 ************************************************/
		CerHouseholderDto oldCerHouseholder = this.getSqlSession().selectOne(
				"CerHouseholderSearchMapper.selectByPrimaryKey",
				cerHouseholderID);
		if (oldCerHouseholder == null) {
			throw new AppBizException(CodeConst.BIS_CODE_68001,
					InfoConst.BIS_INFO_68001);
		}

		if (TypeConst.FLAG_OFF.equals(oldCerHouseholder.getItemStat())) {

			throw new AppBizException(CodeConst.BIS_CODE_68001,
					InfoConst.BIS_INFO_68001);
		}
		return oldCerHouseholder;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int deleteCerHouseholderByLogic(String cerHouseholderID)
			throws AppBizException {

		if (StringUtils.isBlank(cerHouseholderID)) {
			throw new AppBizException(CodeConst.SYS_CODE_1001, "ID不可为空");
		}
		/************************************************
		 * 判断实体是否存在
		 ************************************************/
		CerHouseholderDto oldCerHouseholder = this
				.findCerHouseholderByID(cerHouseholderID);

		oldCerHouseholder.setItemStat(TypeConst.FLAG_OFF);
		oldCerHouseholder.setTsedit(new Date());
		return this.getSqlSession().update(
				"CerHouseholderMapper.updateByPrimaryKeySelective",
				oldCerHouseholder);
	}

	@Override
	public List<Map<String, Object>> findCerHouseholderByPage(String tsCreate,
			String search, int pageNo, int pageSize) throws AppBizException {

		/************************************************
		 * 设置输入参数
		 ************************************************/
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("tsCreate", tsCreate);
		map.put("search", search);
		PageHelper.startPage(pageNo, pageSize);
		List<Map<String, Object>> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.findAllCerHouseholder", map);
		return list;
	}

	@Override
	public List<CerHouseholderDto> getCerHouseholderByPage(String tsCreate,
			String search, int pageNo, int pageSize) throws AppBizException {
		/************************************************
		 * 设置输入参数
		 ************************************************/
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("tsCreate", tsCreate);
		map.put("search", search);
		PageHelper.startPage(pageNo, pageSize);
		List<CerHouseholderDto> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.getAllCerHouseholderDto", map);
		return list;
	}

	@Override
	public List<Map<String, Object>> selectCerHouseholderByRelevantID(
			String householderID, String apartmentID, String type,
			String linkAptHouseholderID, String name, String phone,
			String ownerID) throws AppBizException {
		/************************************************
		 * 设置输入参数
		 ************************************************/
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("householderID", householderID);
		map.put("apartmentID", apartmentID);
		map.put("type", type);
		map.put("linkAptHouseholderID", linkAptHouseholderID);
		map.put("name", name);
		map.put("ownerID", ownerID);
		map.put("phone", phone);

		List<Map<String, Object>> list = this
				.getSqlSession()
				.selectList(
						"CerHouseholderSearchMapper.selectCerHouseholderDtoyRelevantID",
						map);
		return list;
	}

	@Override
	public List<CerHouseholderDto> findCerHouseholderByRelevantID(
			String householderID, String apartmentID, String type,
			String linkAptHouseholderID, String name, String phone,
			String ownerID) throws AppBizException {
		/************************************************
		 * 设置输入参数
		 ************************************************/
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("householderID", householderID);
		map.put("apartmentID", apartmentID);
		map.put("type", type);
		map.put("linkAptHouseholderID", linkAptHouseholderID);

		map.put("name", name);
		map.put("phone", phone);
		map.put("ownerID", ownerID);
		List<CerHouseholderDto> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.findCerHouseholderDtoByRelevantID",
				map);
		return list;
	}

	@Override
	public List<CerHouseholderDto> bauthfindCerHouseholder(
			List<String> cerHouseholderIDs) throws AppBizException {
		/************************************************
		 * 设置输入参数
		 ************************************************/
		List<CerHouseholderDto> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.batchFindCerHouseholder",
				cerHouseholderIDs);
		return list;
	}

	@Override
	public List<Map<String, Object>> bauthfindCerHouseholderByMap(
			Map<String, Object> cerHouseholder) throws AppBizException {
		/************************************************
		 * 设置输入参数
		 ************************************************/
		List<Map<String, Object>> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.batchFindCerHouseholderByMap",
				cerHouseholder);
		return list;
	}

	@Override
	public int deleteCerHouseholderBylinkID(String linkAptHouseholderID)
			throws AppBizException {
		logger.info("在" + new Date() + "删除授权ID为" + linkAptHouseholderID
				+ "的授权信息");
		return this.getSqlSession().update(
				"CerHouseholderMapper.deleteCerHouseholderBylinkID",
				linkAptHouseholderID);

	}

	@Override
	public int addCerHouseholder(List<CerHouseholderDto> cerHouseholder)
			throws AppBizException {
		if (cerHouseholder != null && cerHouseholder.size() > 0) {
			return this.getSqlSession().insert(
					"CerHouseholderBauthMapper.bauthInsert", cerHouseholder);
		}

		return 0;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int addProperty(Map<String, Object> paMap) throws AppBizException {
		if (paMap.containsKey("propertyInfo")) {
			JSONArray propertyInfo = JSONArray.fromObject(paMap.get(
					"propertyInfo").toString());
			for (int i = 0; i < propertyInfo.size(); i++) {
				PropFeeBuildingDto propFeeBuilding = new PropFeeBuildingDto();
				PropFeeUnitDto propFeeUnit = new PropFeeUnitDto();
				PropFeeApartmentDto propFeeApartment = new PropFeeApartmentDto();

				/***
				 * 添加楼栋
				 */

				if (propertyInfo.getJSONObject(i).containsKey("cmmBuilding")) {
					JSONObject cmmBuilding = propertyInfo.getJSONObject(i)
							.getJSONObject("cmmBuilding");
					propFeeBuilding
							.setBuildingID(cmmBuilding.get("buildingID") != null ? cmmBuilding
									.getString("buildingID") : null);
					propFeeBuilding
							.setCommID(cmmBuilding.get("commID") != null ? cmmBuilding
									.getString("commID") : null);

					propFeeBuilding.setBuildingName(cmmBuilding
							.get("buildingName") != null ? cmmBuilding
							.getString("buildingName") : null);
					propFeeBuilding.setBuildingNameOther(cmmBuilding
							.get("buildingNameOther") != null ? cmmBuilding
							.getString("buildingNameOther") : null);

					propFeeBuilding.setBuildingSort(cmmBuilding
							.get("buildingSort") != null ? Integer
							.parseInt(cmmBuilding.getString("buildingSort"))
							: null);

					propFeeBuilding.setBuildingType(cmmBuilding
							.get("buildingType") != null ? cmmBuilding
							.getString("buildingType") : null);

					propFeeBuilding
							.setStatus(cmmBuilding.get("status") != null ? cmmBuilding
									.getString("status") : null);

					List<PropFeeBuildingDto> cmmBuildings = propFeeBuildingService
							.findPropFeeBuildingByRelevantID(
									propFeeBuilding.getBuildingID(),
									propFeeBuilding.getCommID(), null, null,
									propFeeBuilding.getBuildingName());

					if (cmmBuildings == null || cmmBuildings.size() <= 0) {
						propFeeBuildingService
								.addPropFeeBuilding(propFeeBuilding);
					}
				}
				/***
				 * 添加单元
				 */

				if (propertyInfo.getJSONObject(i).containsKey("cmmUnit")) {
					JSONObject cmmUnit = propertyInfo.getJSONObject(i)
							.getJSONObject("cmmUnit");
					propFeeUnit
							.setBuildingID(cmmUnit.get("buildingID") != null ? cmmUnit
									.getString("buildingID") : null);
					propFeeUnit
							.setUnitID(cmmUnit.get("unitID") != null ? cmmUnit
									.getString("unitID") : null);
					propFeeUnit
							.setUnitName(cmmUnit.get("unitName") != null ? cmmUnit
									.getString("unitName") : null);

					List<PropFeeUnitDto> units = propFeeUnitService
							.findPropFeeUnitByRelevantID(
									propFeeUnit.getUnitID(),
									propFeeUnit.getBuildingID(),
									propFeeUnit.getUnitName());
					if (units == null || units.size() <= 0) {
						propFeeUnitService.addPropFeeUnit(propFeeUnit);
					}
				}

				/***
				 * 添加房屋
				 */

				if (propertyInfo.getJSONObject(i).containsKey("cmmApartments")) {
					JSONObject cmmApartments = propertyInfo.getJSONObject(i)
							.getJSONObject("cmmApartments");
					propFeeApartment.setApartmentID(cmmApartments
							.get("apartmentID") != null ? cmmApartments
							.getString("apartmentID") : null);
					propFeeApartment.setApartmentNum(cmmApartments
							.get("apartmentNumb") != null ? cmmApartments
							.getString("apartmentNumb") : null);
					propFeeApartment.setApartmentType(cmmApartments
							.get("apartmentType") != null ? cmmApartments
							.getString("apartmentType") : null);
					propFeeApartment.setBuildingID(cmmApartments
							.get("buildingID") != null ? cmmApartments
							.getString("buildingID") : null);
					propFeeApartment
							.setFeeArea(cmmApartments.get("feeArea") != null ? cmmApartments
									.getString("feeArea") : null);
					propFeeApartment.setBuildingArea(cmmApartments
							.get("buildingArea") != null ? cmmApartments
							.getString("buildingArea") : null);

					propFeeApartment.setPropertyArea(cmmApartments
							.get("propertyArea") != null ? cmmApartments
							.getString("propertyArea") : null);
					propFeeApartment
							.setFloor(cmmApartments.get("floor") != null ? cmmApartments
									.getString("floor") : null);
					propFeeApartment.setIsDeliver(cmmApartments
							.get("isDeliver") != null ? cmmApartments
							.getString("isDeliver") : null);
					propFeeApartment
							.setIsOccupy(cmmApartments.get("isOccupy") != null ? cmmApartments
									.getString("isOccupy") : null);
					propFeeApartment
							.setUnitID(cmmApartments.get("unitID") != null ? cmmApartments
									.getString("unitID") : null);
					propFeeApartment
							.setSourceID(cmmApartments.get("sourceID") != null ? cmmApartments
									.getString("sourceID") : null);
					propFeeApartment.setOtherName(cmmApartments.get("otherName") != null ? cmmApartments
							.getString("otherName") : null);//添加别名
							propFeeApartment.setCreateuserID(cmmApartments.get("createuserID") != null ? cmmApartments
									.getString("createuserID") : null);//添加创建者

					if (cmmApartments.get("joinTime") != null) {
						String jsonTime = cmmApartments.getString("joinTime");
						if (!StringUtils.isBlank(jsonTime)
								&& !"null".equals(jsonTime)) {

							JSONObject json = JSONObject.fromObject(jsonTime);
							propFeeApartment.setJoinTime(new Date(Long
									.parseLong(json.getString("time"))));
						}
					}
					List<PropFeeApartmentDto> apartments = propFeeApartmentService
							.findPropFeeApartmentByRelevantID(
									propFeeApartment.getApartmentID(),
									propFeeApartment.getSourceID(),
									propFeeApartment.getBuildingID(),
									propFeeApartment.getUnitID(), null,
									propFeeApartment.getApartmentType(),
									propFeeApartment.getApartmentNum());
					if (apartments == null || apartments.size() <= 0) {
						propFeeApartmentService
								.addPropFeeApartment(propFeeApartment);
					}
				}

				if (propertyInfo.getJSONObject(i).containsKey("owners")) {
					JSONArray owners = propertyInfo.getJSONObject(i)
							.getJSONArray("owners");
					for (int j = 0; j < owners.size(); j++) {

						if (owners.getJSONObject(j).containsKey("owner")) {
							JSONObject owner = owners.getJSONObject(j)
									.getJSONObject("owner");
							List<CerHouseholderDto> cerHouseholderDtos = this
									.findCerHouseholderByRelevantID(null,
											propFeeApartment.getApartmentID(),
											"0", null, owner.getString("name"),
											owner.getString("phone"), null);
							if (cerHouseholderDtos != null
									&& cerHouseholderDtos.size() > 0) {
								continue;
							}
							/***
							 * 添加业主关系
							 */

							CerHouseholderDto cerHouseholder = new CerHouseholderDto();
							cerHouseholder.setName(owner.getString("name"));
							cerHouseholder.setPhone(owner.getString("phone"));
							cerHouseholder.setApartmentID(propFeeApartment
									.getApartmentID());
							JSONObject linkPropertyHouseholder = owners
									.getJSONObject(j).getJSONObject(
											"linkPropertyHouseholder");
							cerHouseholder.setType(linkPropertyHouseholder
									.getString("type"));
							cerHouseholder
									.setLinkAptHouseholderID(linkPropertyHouseholder
											.getString("linkAptHouseholderID"));
							this.addCerHouseholder(cerHouseholder);
						}
					}
				}

			}

		}
		return 0;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int addOwners(Map<String, Object> paMap) throws AppBizException {
		JSONObject jsonObject = JSONObject.fromObject(paMap);
		if (jsonObject != null) {
			/****
			 * 添加业主
			 */
			CerHouseholderDto cerHouseholderDto = new CerHouseholderDto();
			cerHouseholderDto.setApartmentID(jsonObject
					.getString("apartmentID"));
			cerHouseholderDto.setLinkAptHouseholderID(jsonObject
					.getString("linkAptHouseholderID"));
			cerHouseholderDto.setName(jsonObject.getString("name"));
			cerHouseholderDto.setPhone(jsonObject.getString("phone"));
			cerHouseholderDto.setType(jsonObject.getString("type"));
			cerHouseholderDto.setOwnerID(jsonObject.getString("ownersID"));

			List<CerHouseholderDto> cerHouseholderDtos = this
					.findCerHouseholderByRelevantID(null,
							cerHouseholderDto.getApartmentID(),
							cerHouseholderDto.getType(),
							cerHouseholderDto.getLinkAptHouseholderID(), null,
							null, null);
			if (cerHouseholderDtos != null && cerHouseholderDtos.size() > 0) {
				logger.error("该业主信息已经存在(消息体 "
						+ JSONObject.fromObject(paMap).toString() + ")");
				throw new AppBizException(2, "该业主信息已经存在");
			}
			this.addCerHouseholder(cerHouseholderDto);

			System.out.println(JSONObject.fromObject(paMap).toString());
			logger.info("在" + new Date() + "添加业主信息(消息体 "
					+ JSONObject.fromObject(paMap.get("ownerInfo")).toString()
					+ ")");
		}
		return 0;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editOwners(Map<String, Object> paMap) throws AppBizException {
		JSONObject jsonObject = JSONObject.fromObject(paMap);

		if (jsonObject != null) {
			/****
			 * 修改业主
			 */
			CerHouseholderDto cerHouseholderDto = new CerHouseholderDto();
			cerHouseholderDto.setApartmentID(jsonObject
					.getString("apartmentID"));
			cerHouseholderDto.setLinkAptHouseholderID(jsonObject
					.getString("linkAptHouseholderID"));
			cerHouseholderDto.setName(jsonObject.getString("name"));
			cerHouseholderDto.setPhone(jsonObject.getString("phone"));
			cerHouseholderDto.setType(jsonObject.getString("type"));

			List<CerHouseholderDto> cerHouseholderDtos = this
					.findCerHouseholderByRelevantID(null,
							cerHouseholderDto.getApartmentID(),
							cerHouseholderDto.getType(),
							cerHouseholderDto.getLinkAptHouseholderID(), null,
							null, null);
			if (cerHouseholderDtos != null && cerHouseholderDtos.size() > 1) {
				logger.error("该业主信息已经存在(消息体 "
						+ JSONObject.fromObject(paMap).toString() + ")");
				throw new AppBizException(2, "该业主信息已经存在");
			}

			if (cerHouseholderDtos != null && cerHouseholderDtos.size() > 0) {
				cerHouseholderDto.setHouseholderID(cerHouseholderDtos.get(0)
						.getHouseholderID());
				cerHouseholderDto.setIsOwner(jsonObject.getString("isOwner"));
				this.editCerHouseholder(cerHouseholderDto);
			}
			logger.info("在" + new Date() + "修改业主信息(消息体 "
					+ JSONObject.fromObject(paMap.get("ownerInfo")).toString()
					+ ")");
		}
		return 0;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editProperty(Map<String, Object> paMap) throws AppBizException {
		PropFeeApartmentDto propFeeApartment = new PropFeeApartmentDto();

		/***
		 * 修改产权信息
		 */

		JSONObject cmmApartments = JSONObject.fromObject(paMap);
		if (cmmApartments != null) {
			propFeeApartment
					.setApartmentID(cmmApartments.get("apartmentID") != null ? cmmApartments
							.getString("apartmentID") : null);
			propFeeApartment
					.setFeeArea(cmmApartments.get("feeArea") != null ? cmmApartments
							.getString("feeArea") : null);
			propFeeApartment
					.setBuildingArea(cmmApartments.get("buildingArea") != null ? cmmApartments
							.getString("buildingArea") : null);
			propFeeApartment
					.setPropertyArea(cmmApartments.get("propertyArea") != null ? cmmApartments
							.getString("propertyArea") : null);
			propFeeApartment
					.setFloor(cmmApartments.get("floor") != null ? cmmApartments
							.getString("floor") : null);
			propFeeApartment
					.setIsDeliver(cmmApartments.get("isDeliver") != null ? cmmApartments
							.getString("isDeliver") : null);
			propFeeApartment
					.setIsOccupy(cmmApartments.get("isOccupy") != null ? cmmApartments
							.getString("isOccupy") : null);

			propFeeApartment.setApartmentType(cmmApartments
					.get("apartmentType") != null ? cmmApartments
					.getString("apartmentType") : null);
			if (cmmApartments.get("joinTime") != null) {
				String jsonTime = cmmApartments.getString("joinTime");
				if (!StringUtils.isBlank(jsonTime) && !"null".equals(jsonTime)) {

					propFeeApartment.setJoinTime(new Date(
							Long.parseLong(cmmApartments.get("joinTime")
									.toString())));
				}
			}
			return propFeeApartmentService
					.editPropFeeApartment(propFeeApartment);
		}
		return 1;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int importProperty(Map<String, Object> paMap) throws AppBizException {
		JSONObject propertyInfo = JSONObject.fromObject(paMap.get("houseInfo"));

		PropFeeBuildingDto propFeeBuilding = new PropFeeBuildingDto();
		PropFeeUnitDto propFeeUnit = new PropFeeUnitDto();
		PropFeeApartmentDto propFeeApartment = new PropFeeApartmentDto();
		/***
		 * 添加楼栋
		 */

		if (propertyInfo.containsKey("cmmBuilding")) {
			JSONObject cmmBuilding = propertyInfo.getJSONObject("cmmBuilding");
			propFeeBuilding
					.setBuildingID(cmmBuilding.get("buildingID") != null ? cmmBuilding
							.getString("buildingID") : null);
			propFeeBuilding
					.setCommID(cmmBuilding.getString("commID") != null ? cmmBuilding
							.getString("commID") : null);
			propFeeBuilding
					.setBuildingName(cmmBuilding.get("buildingName") != null ? cmmBuilding
							.getString("buildingName") : null);
			propFeeBuilding.setBuildingNameOther(cmmBuilding
					.get("buildingNameOther") != null ? cmmBuilding
					.getString("buildingNameOther") : null);
			propFeeBuilding
					.setBuildingSort(cmmBuilding.get("buildingSort") != null ? Integer
							.parseInt(cmmBuilding.getString("buildingSort"))
							: null);
			propFeeBuilding
					.setBuildingType(cmmBuilding.get("buildingType") != null ? cmmBuilding
							.getString("buildingType") : null);
			propFeeBuilding
					.setStatus(cmmBuilding.get("status") != null ? cmmBuilding
							.getString("status") : null);

			Map<String, Object> buildMap = new HashMap<>();
			buildMap.put("buildingName", propFeeBuilding.getBuildingName());
			buildMap.put("commID", propFeeBuilding.getCommID());
			List<Map<String, Object>> buildings = propFeeBuildingService
					.bauthfindPropFeeBuildingByMap(buildMap);
			if (buildings == null || buildings.size() <= 0) {
				propFeeBuildingService.addPropFeeBuilding(propFeeBuilding);
			}
		}

		if (propertyInfo.containsKey("cmmUnit")) {
			/***
			 * 添加单元
			 */
			JSONObject cmmUnit = propertyInfo.getJSONObject("cmmUnit");

			propFeeUnit
					.setBuildingID(cmmUnit.get("buildingID") != null ? cmmUnit
							.getString("buildingID") : null);
			propFeeUnit.setUnitID(cmmUnit.get("unitID") != null ? cmmUnit
					.getString("unitID") : null);
			propFeeUnit
					.setUnitName(cmmUnit.getString("unitName") != null ? cmmUnit
							.getString("unitName") : null);

			Map<String, Object> unitPa = new HashMap<>();
			unitPa.put("unitName", propFeeUnit.getUnitName());
			unitPa.put("buildingID", propFeeUnit.getBuildingID());
			List<Map<String, Object>> units = propFeeUnitService
					.bauthfindPropFeeUnitByMap(unitPa);
			if (units == null || units.size() <= 0) {
				propFeeUnitService.addPropFeeUnit(propFeeUnit);
			}
		}

		/***
		 * 添加房屋
		 */

		if (propertyInfo.containsKey("cmmApartments")) {
			JSONObject cmmApartments = propertyInfo
					.getJSONObject("cmmApartments");
			propFeeApartment
					.setApartmentID(cmmApartments.get("apartmentID") != null ? cmmApartments
							.getString("apartmentID") : null);
			propFeeApartment
					.setApartmentNum(cmmApartments.get("apartmentNumb") != null ? cmmApartments
							.getString("apartmentNumb") : null);
			propFeeApartment.setApartmentType(cmmApartments
					.get("apartmentType") != null ? cmmApartments
					.getString("apartmentType") : null);
			propFeeApartment
					.setBuildingID(cmmApartments.get("buildingID") != null ? cmmApartments
							.getString("buildingID") : null);
			propFeeApartment
					.setFeeArea(cmmApartments.get("feeArea") != null ? cmmApartments
							.getString("feeArea") : null);
			propFeeApartment
					.setBuildingArea(cmmApartments.get("buildingArea") != null ? cmmApartments
							.getString("buildingArea") : null);
			propFeeApartment
					.setPropertyArea(cmmApartments.get("propertyArea") != null ? cmmApartments
							.getString("propertyArea") : null);
			propFeeApartment
					.setFloor(cmmApartments.getString("floor") != null ? cmmApartments
							.getString("floor") : null);
			propFeeApartment
					.setIsDeliver(cmmApartments.get("isDeliver") != null ? cmmApartments
							.getString("isDeliver") : null);
			propFeeApartment
					.setIsOccupy(cmmApartments.get("isOccupy") != null ? cmmApartments
							.getString("isOccupy") : null);
			if (cmmApartments.containsKey("unitID")) {
				if (cmmApartments.get("unitID") != null) {
					propFeeApartment.setUnitID(cmmApartments
							.getString("unitID"));
				}
			}
			if (cmmApartments.get("joinTime") != null) {
				String jsonTime = cmmApartments.getString("joinTime");
				if (!StringUtils.isBlank(jsonTime) && !"null".equals(jsonTime)) {

					propFeeApartment.setJoinTime(new Date(Long
							.parseLong(jsonTime)));
				}
			}
			propFeeApartment.setOtherName(cmmApartments.get("otherName") != null ? cmmApartments
					.getString("otherName") : null);//添加别名

			propFeeApartment
					.setSourceID(cmmApartments.get("sourceID") != null ? cmmApartments
							.getString("sourceID") : null);
			Map<String, Object> apartmentsPa = new HashMap<>();
			apartmentsPa
					.put("apartmentNum", propFeeApartment.getApartmentNum());
			// map2.put("floorID",
			// cmmApartmentsDto.getFloorID());
			apartmentsPa.put("unitID", propFeeApartment.getUnitID());
			apartmentsPa.put("buildingID", propFeeApartment.getBuildingID());
			List<Map<String, Object>> apartments = propFeeApartmentService
					.bauthfindPropFeeApartmentByMap(apartmentsPa);
			if (apartments == null || apartments.size() <= 0) {
				propFeeApartmentService.addPropFeeApartment(propFeeApartment);
			} else {
				propFeeApartmentService.editPropFeeApartment(propFeeApartment);
			}
		}

		if (propertyInfo.containsKey("owners")) {
			JSONArray owners = propertyInfo.getJSONArray("owners");
			for (int j = 0; j < owners.size(); j++) {
				JSONObject owner = owners.getJSONObject(j).getJSONObject(
						"owner");

				JSONObject linkPropertyHouseholder = owners.getJSONObject(j)
						.getJSONObject("linkPropertyHouseholder");
				List<CerHouseholderDto> cerHouseholderDtos = this
						.findCerHouseholderByRelevantID(
								null,
								propFeeApartment.getApartmentID(),
								"0",
								linkPropertyHouseholder
										.getString("linkAptHouseholderID"),
								owner.getString("name"),
								owner.getString("phone"),
								owner.get("ownersID") != null ? owner
										.getString("ownersID") : null);
				if (cerHouseholderDtos != null && cerHouseholderDtos.size() > 0) {
					continue;
				}

				/***
				 * 添加业主关系
				 */

				CerHouseholderDto cerHouseholder = new CerHouseholderDto();
				cerHouseholder.setName(owner.getString("name"));
				cerHouseholder.setOwnerID(owner.get("ownersID") != null ? owner
						.getString("ownersID") : null);
				cerHouseholder.setPhone(owner.getString("phone"));
				cerHouseholder
						.setApartmentID(propFeeApartment.getApartmentID());

				cerHouseholder.setType(linkPropertyHouseholder
						.getString("type"));
				cerHouseholder.setLinkAptHouseholderID(linkPropertyHouseholder
						.getString("linkAptHouseholderID"));
				this.addCerHouseholder(cerHouseholder);
			}
		}
		return 0;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int changeOwner(Map<String, Object> paMap) throws AppBizException {

		return 0;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editComm(Map<String, Object> paMap) throws AppBizException {

		PropFeeCommDto propFeeCommDto = new PropFeeCommDto();
		if (!paMap.containsKey("commID")) {
			throw new AppBizException(2, "亲小区信息");
		}
		if (!paMap.containsKey("comm")) {
			throw new AppBizException(2, "亲小区信息");
		}
		propFeeCommDto.setComm(paMap.get("comm").toString());
		propFeeCommDto.setCommID(paMap.get("commID").toString());
		propFeeCommDto.setRemark(paMap.get("comm").toString());
		return propFeeCommService.editPropFeeComm(propFeeCommDto);
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editBuilding(Map<String, Object> paMap) throws AppBizException {

		JSONObject jsonObject = JSONObject.fromObject(paMap);
		if (jsonObject != null) {
			PropFeeBuildingDto propFeeBuilding = new PropFeeBuildingDto();
			propFeeBuilding
					.setBuildingID(jsonObject.get("buildingID") != null ? jsonObject
							.getString("buildingID") : null);
			propFeeBuilding
					.setBuildingName(jsonObject.get("buildingName") != null ? jsonObject
							.getString("buildingName") : null);
			propFeeBuilding.setBuildingNameOther(jsonObject
					.get("buildingNameOther") != null ? jsonObject
					.getString("buildingNameOther") : null);
			propFeeBuilding
					.setBuildingType(jsonObject.get("buildingType") != null ? jsonObject
							.getString("buildingType") : null);

			propFeeBuilding
					.setStatus(jsonObject.get("status") != null ? jsonObject
							.getString("status") : null);
			propFeeBuilding
					.setCommID(jsonObject.get("commID") != null ? jsonObject
							.getString("commID") : null);
			propFeeBuilding
					.setEdituserID(jsonObject.get("edituserID") != null ? jsonObject
							.getString("edituserID") : null);

			List<PropFeeBuildingDto> cmmBuildings = propFeeBuildingService
					.findPropFeeBuildingByRelevantID(
							propFeeBuilding.getBuildingID(),
							propFeeBuilding.getCommID(), null, null,
							propFeeBuilding.getBuildingName());

			if (cmmBuildings != null && cmmBuildings.size() <= 1) {
				return propFeeBuildingService
						.editPropFeeBuilding(propFeeBuilding);
			}

		}
		return 1;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int addBuilding(Map<String, Object> paMap) throws AppBizException {

		JSONObject jsonObject = JSONObject.fromObject(paMap);
		if (jsonObject != null) {
			PropFeeBuildingDto propFeeBuilding = new PropFeeBuildingDto();
			propFeeBuilding
					.setBuildingID(jsonObject.get("buildingID") != null ? jsonObject
							.getString("buildingID") : null);
			propFeeBuilding
					.setBuildingName(jsonObject.get("buildingName") != null ? jsonObject
							.getString("buildingName") : null);
			propFeeBuilding.setBuildingNameOther(jsonObject
					.get("buildingNameOther") != null ? jsonObject
					.getString("buildingNameOther") : null);
			propFeeBuilding
					.setBuildingType(jsonObject.get("buildingType") != null ? jsonObject
							.getString("buildingType") : null);

			propFeeBuilding
					.setStatus(jsonObject.get("status") != null ? jsonObject
							.getString("status") : null);
			propFeeBuilding
					.setCommID(jsonObject.get("commID") != null ? jsonObject
							.getString("commID") : null);
			propFeeBuilding
					.setEdituserID(jsonObject.get("edituserID") != null ? jsonObject
							.getString("edituserID") : null);

			List<PropFeeBuildingDto> cmmBuildings = propFeeBuildingService
					.findPropFeeBuildingByRelevantID(
							propFeeBuilding.getBuildingID(),
							propFeeBuilding.getCommID(), null, null,
							propFeeBuilding.getBuildingName());

			if (cmmBuildings == null || cmmBuildings.size() <= 0) {
				return propFeeBuildingService
						.addPropFeeBuilding(propFeeBuilding);
			}
		}
		return 1;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int deleteBuilding(String buildingID) throws AppBizException {

		return propFeeBuildingService.deletePropFeeBuildingByLogic(buildingID);
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthDeleteBuilding(Map<String, Object> paMap)
			throws AppBizException {

		return this.getSqlSession().update(
				"PropFeeBuildingBauthMapper.bauthDeleteLg",
				paMap.get("buildingIDs"));
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editUnit(Map<String, Object> paMap) throws AppBizException {
		/***
		 * 添加单元
		 */
		JSONObject cmmUnit = JSONObject.fromObject(paMap);
		if (cmmUnit != null) {
			PropFeeUnitDto propFeeUnit = new PropFeeUnitDto();
			propFeeUnit
					.setBuildingID(cmmUnit.get("buildingID") != null ? cmmUnit
							.getString("buildingID") : null);
			propFeeUnit.setUnitID(cmmUnit.get("unitID") != null ? cmmUnit
					.getString("unitID") : null);
			propFeeUnit.setUnitName(cmmUnit.get("unitName") != null ? cmmUnit
					.getString("unitName") : null);
			propFeeUnit
					.setCreateuserID(cmmUnit.getString("createuserID") != null ? cmmUnit
							.getString("createuserID") : null);
			Map<String, Object> unitPa = new HashMap<>();
			unitPa.put("unitName", propFeeUnit.getUnitName());
			unitPa.put("buildingID", propFeeUnit.getBuildingID());
			List<Map<String, Object>> units = propFeeUnitService
					.bauthfindPropFeeUnitByMap(unitPa);
			if (units != null && units.size() <= 1) {
				return propFeeUnitService.editPropFeeUnit(propFeeUnit);
			}

		}
		return 1;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int addUnit(Map<String, Object> paMap) throws AppBizException {
		/***
		 * 添加单元
		 */
		JSONObject cmmUnit = JSONObject.fromObject(paMap);
		if (cmmUnit != null) {
			PropFeeUnitDto propFeeUnit = new PropFeeUnitDto();
			propFeeUnit
					.setBuildingID(cmmUnit.get("buildingID") != null ? cmmUnit
							.getString("buildingID") : null);
			propFeeUnit.setUnitID(cmmUnit.get("unitID") != null ? cmmUnit
					.getString("unitID") : null);
			propFeeUnit.setUnitName(cmmUnit.get("unitName") != null ? cmmUnit
					.getString("unitName") : null);
			propFeeUnit
					.setCreateuserID(cmmUnit.get("createuserID") != null ? cmmUnit
							.getString("createuserID") : null);
			Map<String, Object> unitPa = new HashMap<>();
			unitPa.put("unitName", propFeeUnit.getUnitName());
			unitPa.put("buildingID", propFeeUnit.getBuildingID());
			List<Map<String, Object>> units = propFeeUnitService
					.bauthfindPropFeeUnitByMap(unitPa);
			if (units == null || units.size() <= 0) {
				return propFeeUnitService.addPropFeeUnit(propFeeUnit);
			}

		}
		return 1;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int deleteUnit(String unitID) throws AppBizException {

		return propFeeUnitService.deletePropFeeUnitByLogic(unitID);
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthDeleteUnit(Map<String, Object> paMap)
			throws AppBizException {
		return this.getSqlSession().update(
				"PropFeeUnitBauthMapper.bauthDeleteLg", paMap.get("unitIDs"));
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int editApartment(Map<String, Object> paMap) throws AppBizException {

		JSONObject cmmApartments = JSONObject.fromObject(paMap);
		if (cmmApartments != null) {
			PropFeeApartmentDto propFeeApartment = new PropFeeApartmentDto();
			propFeeApartment
					.setApartmentID(cmmApartments.get("apartmentID") != null ? cmmApartments
							.getString("apartmentID") : null);
			propFeeApartment
					.setApartmentNum(cmmApartments.get("apartmentNumb") != null ? cmmApartments
							.getString("apartmentNumb") : null);
			propFeeApartment.setApartmentType(cmmApartments
					.get("apartmentType") != null ? cmmApartments
					.getString("apartmentType") : null);
			propFeeApartment
					.setBuildingID(cmmApartments.get("buildingID") != null ? cmmApartments
							.getString("buildingID") : null);
			propFeeApartment
					.setFeeArea(cmmApartments.get("feeArea") != null ? cmmApartments
							.getString("feeArea") : null);
			propFeeApartment
					.setBuildingArea(cmmApartments.get("buildingArea") != null ? cmmApartments
							.getString("buildingArea") : null);
			propFeeApartment
					.setPropertyArea(cmmApartments.get("propertyArea") != null ? cmmApartments
							.getString("propertyArea") : null);
			propFeeApartment
					.setFloor(cmmApartments.get("floor") != null ? cmmApartments
							.getString("floor") : null);
			propFeeApartment
					.setIsDeliver(cmmApartments.get("isDeliver") != null ? cmmApartments
							.getString("isDeliver") : null);
			propFeeApartment
					.setIsOccupy(cmmApartments.get("isOccupy") != null ? cmmApartments
							.getString("isOccupy") : null);
			if (cmmApartments.containsKey("unitID")) {
				if (cmmApartments.get("unitID") != null) {
					propFeeApartment.setUnitID(cmmApartments
							.getString("unitID"));
				}
			}
			propFeeApartment
					.setSourceID(cmmApartments.get("sourceID") != null ? cmmApartments
							.getString("sourceID") : null);
			if (cmmApartments.get("joinTime") != null) {
				String jsonTime = cmmApartments.getString("joinTime");
				if (!StringUtils.isBlank(jsonTime) && !"null".equals(jsonTime)) {

					JSONObject jsonObject = JSONObject.fromObject(jsonTime);

					propFeeApartment.setJoinTime(new Date(Long
							.parseLong(jsonObject.getString("time"))));
				}
			}

			Map<String, Object> apartmentsPa = new HashMap<>();
			apartmentsPa
					.put("apartmentNum", propFeeApartment.getApartmentNum());
			// map2.put("floorID",
			// cmmApartmentsDto.getFloorID());
			apartmentsPa.put("unitID", propFeeApartment.getUnitID());
			apartmentsPa.put("buildingID", propFeeApartment.getBuildingID());
			List<Map<String, Object>> apartments = propFeeApartmentService
					.bauthfindPropFeeApartmentByMap(apartmentsPa);
			if (apartments != null && apartments.size() <= 1) {
				return propFeeApartmentService
						.editPropFeeApartment(propFeeApartment);
			}

		}
		return 1;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int addApartment(Map<String, Object> paMap) throws AppBizException {

		JSONObject cmmApartments = JSONObject.fromObject(paMap);
		if (cmmApartments != null) {
			PropFeeApartmentDto propFeeApartment = new PropFeeApartmentDto();
			propFeeApartment
					.setApartmentID(cmmApartments.get("apartmentID") != null ? cmmApartments
							.getString("apartmentID") : null);
			propFeeApartment
					.setApartmentNum(cmmApartments.get("apartmentNumb") != null ? cmmApartments
							.getString("apartmentNumb") : null);
			propFeeApartment.setApartmentType(cmmApartments
					.get("apartmentType") != null ? cmmApartments
					.getString("apartmentType") : null);
			propFeeApartment
					.setBuildingID(cmmApartments.get("buildingID") != null ? cmmApartments
							.getString("buildingID") : null);
			propFeeApartment
					.setFeeArea(cmmApartments.get("feeArea") != null ? cmmApartments
							.getString("feeArea") : null);
			propFeeApartment
					.setBuildingArea(cmmApartments.get("buildingArea") != null ? cmmApartments
							.getString("buildingArea") : null);
			propFeeApartment
					.setPropertyArea(cmmApartments.get("propertyArea") != null ? cmmApartments
							.getString("propertyArea") : null);
			propFeeApartment
					.setFloor(cmmApartments.get("floor") != null ? cmmApartments
							.getString("floor") : null);
			propFeeApartment
					.setIsDeliver(cmmApartments.get("isDeliver") != null ? cmmApartments
							.getString("isDeliver") : null);
			propFeeApartment
					.setIsOccupy(cmmApartments.get("isOccupy") != null ? cmmApartments
							.getString("isOccupy") : null);
			if (cmmApartments.containsKey("unitID")) {
				if (cmmApartments.get("unitID") != null) {
					propFeeApartment.setUnitID(cmmApartments
							.getString("unitID"));
				}
			}
			if (cmmApartments.get("joinTime") != null) {
				String jsonTime = cmmApartments.getString("joinTime");
				if (!StringUtils.isBlank(jsonTime) && !"null".equals(jsonTime)) {
					JSONObject jsonObject = JSONObject.fromObject(jsonTime);

					propFeeApartment.setJoinTime(new Date(Long
							.parseLong(jsonObject.getString("time"))));
				}
			}
			propFeeApartment
					.setSourceID(cmmApartments.get("sourceID") != null ? cmmApartments
							.getString("sourceID") : null);

			Map<String, Object> apartmentsPa = new HashMap<>();
			apartmentsPa
					.put("apartmentNum", propFeeApartment.getApartmentNum());
			// map2.put("floorID",
			// cmmApartmentsDto.getFloorID());
			apartmentsPa.put("unitID", propFeeApartment.getUnitID());
			apartmentsPa.put("buildingID", propFeeApartment.getBuildingID());
			List<Map<String, Object>> apartments = propFeeApartmentService
					.bauthfindPropFeeApartmentByMap(apartmentsPa);
			if (apartments == null || apartments.size() <= 0) {
				return propFeeApartmentService
						.addPropFeeApartment(propFeeApartment);
			}
		}
		return 1;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int deleteApartment(String apartmentID) throws AppBizException {

		return propFeeApartmentService
				.deletePropFeeApartmentByLogic(apartmentID);
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthDeleteApartment(Map<String, Object> paMap)
			throws AppBizException {
		return this.getSqlSession().update(
				"PropFeeApartmentBauthMapper.bauthDeleteLg",
				paMap.get("apartmentIDs"));
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthEditBuildingUnit(Map<String, Object> paMap)
			throws AppBizException {
		if (paMap.get("removeType") == null) {
			throw new AppBizException(2, "亲，移动类型 ");

		}

		if (!paMap.get("removeType").toString().equals("1")
				&& !paMap.get("removeType").toString().equals("2")) {
			throw new AppBizException(2, "亲，正确移动类型 ");

		}

		String removeType = paMap.get("removeType").toString();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("unitIDs", paMap.get("unitIDs"));
		map.put("buildingID", paMap.get("newBuildingID"));

		map.put("edituserID", paMap.get("edituserID"));
		if (removeType.equals("1")) {

			/***
			 * 移动单元
			 */
			return this.getSqlSession().update(
					"PropFeeUnitBauthMapper.bauthEditUnit", map);

		}
		if (removeType.equals("2")) {
			map.put("unitIDs", paMap.get("unitIDs"));

			map.put("oldBuildingID", paMap.get("buildingID"));
			map.put("buildingID", paMap.get("newBuildingID"));
			map.put("edituserID", paMap.get("edituserID"));

			/****
			 * 移动房子所属的楼栋
			 */
			this.getSqlSession().update(
					"PropFeeApartmentBauthMapper.bauthEditApartmentInfo", map);

			/***
			 * 移动单元
			 */
			return this.getSqlSession().update(
					"PropFeeUnitBauthMapper.bauthEditUnit", map);

		}
		return 1;

	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthEditUnitApart(Map<String, Object> paMap)
			throws AppBizException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("apartmentIDs", paMap.get("apartmentIDs"));
		map.put("buildingID", paMap.get("newBuildingID"));
		map.put("unitID", paMap.get("unitID") != null ? paMap.get("unitID")
				: null);
		map.put("edituserID", paMap.get("edituserID"));
		return this.getSqlSession().update(
				"PropFeeApartmentBauthMapper.bauthEditApartment", map);
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthDeleteCerHouseholder(List<String> ownerIDs)
			throws AppBizException {
		return this.getSqlSession().update(
				"CerHouseholderBauthMapper.bauthDeleteLg", ownerIDs);

	}

	@Override
	public List<CerHouseholderDto> batchFindCerHouseholders(String commID)
			throws AppBizException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		List<CerHouseholderDto> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.batchFindCerHouseholders", map);
		return list;
	}

	@Override
	public Map<String, Object> getHouseInfo(String apartmentID)
			throws AppBizException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("apartmentID", apartmentID);
		List<Map<String, Object>> list = this.getSqlSession().selectList(
				"CerHouseholderSearchMapper.getHouseInfo", map);

		if (list != null && list.size() > 0) {
			return com.orangelife.utils.PropertyUtils
					.turnToEntity1(list.get(0));
		}
		return map;
	}

	@Override
	public int addComm(Map<String, Object> paMap) throws AppBizException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional(rollbackFor = { AppBizException.class, Exception.class,
			RuntimeException.class })
	public int bauthDeleteCerHouseholderLink(List<String> ownerIDs)
			throws AppBizException {
		return this.getSqlSession().update(
				"CerHouseholderBauthMapper.bauthDeleteOwners", ownerIDs);
	}
}